package com.zy.ivideo.controller;

import com.zy.ivideo.entity.ReplyEntity;
import com.zy.ivideo.entity.ResponseEntity;
import com.zy.ivideo.service.ReplyService;
import com.zy.ivideo.token.PassToken;
import com.zy.ivideo.token.UserToken;
import com.zy.ivideo.utils.ResponseUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reply")
@Api(value = "回复模块API接口", description = "该模块提供回复模块服务", tags = "回复模块")
public class ReplyController {
    @Autowired
    ReplyService service;

    /**
     * 回复评论
     * @param entity
     * @return
     */
    @UserToken
    @ApiOperation(value = "回复评论", notes = "回复评论", httpMethod = "POST")
    @PostMapping("/reply")
    public ResponseEntity<ReplyEntity> reply(@RequestBody
                                                 @ApiParam(value = "回复实体", name = "entity", required = true)
                                                         ReplyEntity entity){
        return service.reply(entity);
    }

    /**
     * 删除回复
     * @param id
     * @return
     */
    @UserToken
    @ApiOperation(value = "删除回复", notes = "删除回复", httpMethod = "DELETE")
    @DeleteMapping("/removeReply")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "id", value = "回复id", required = true),
    })
    public ResponseEntity<Boolean> removeReply(Long id){
        return service.removeReply(id);
    }

    /**
     * 根据评论id获取回复信息
     * @param commentid
     * @return
     */
    @PassToken
    @ApiOperation(value = "根据评论id获取回复信息", notes = "根据评论id获取回复信息", httpMethod = "GET")
    @GetMapping("/getReplyByCommentId")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "commentid", value = "评论id", required = true),
    })
    public ResponseEntity<List<ReplyEntity>> getReplyByCommentId(long commentid){
        return service.getReplyByCommentId(commentid);
    }

    /**
     * 点赞
     * @param replyid
     * @return
     */
    @UserToken
    @ApiOperation(value = "点赞", notes = "点赞", httpMethod = "POST")
    @PostMapping("/agree")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "replyid", value = "回复id", required = true),
    })
    public ResponseEntity<Boolean> agree(int replyid){
        return service.agree(replyid);
    }

    /**
     * 取消点赞
     * @param replyid
     * @return
     */
    @UserToken
    @ApiOperation(value = "取消点赞", notes = "取消点赞", httpMethod = "POST")
    @PostMapping("/unAgree")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "replyid", value = "回复id", required = true),
    })
    public ResponseEntity<Boolean> unAgree(int replyid){
        return service.unAgree(replyid);
    }
}
